<?php
/**
 * @package Curly
 * @version 0.9
 * @link http://curly.codeplex.com/
 * @license http://curly.codeplex.com/license The MIT License
 * @author Dawid Zawada
 */

namespace Curly
{
    use Curly\Enumeration\Enum;

    /**
     * HTTP response statuses enumeration
     * 
     * @package Curly
     * @license http://curly.codeplex.com/license The MIT License
     */
	final class HttpStatus extends Enum
	{
	    /**
	     * Array of all common statuses with the status codes as keys
	     * 
	     * @var array
	     */
	    private static $statuses = array(
	        100 => "Continue",
    		101 => "Switching Protocols",
    		200 => "OK",
    		201 => "Created",
    		202 => "Accepted",
    		203 => "Non-Authoritative Information",
    		204 => "No Content",
    		205 => "Reset Content",
    		206 => "Partial Content",
    		300 => "Multiple Choices",
    		301 => "Moved Permanently",
    		302 => "Found",
    		303 => "See Other",
    		304 => "Not Modified",
    		305 => "Use Proxy",
    		306 => "Unused",
    		307 => "Temporary Redirect",
    		400 => "Bad Request",
    		401 => "Unauthorized",
    		402 => "Payment Required",
    		403 => "Forbidden",
    		404 => "Not Found",
    		405 => "Method Not Allowed",
    		406 => "Not Acceptable",
    		407 => "Proxy Authentication Required",
    		408 => "Request Timeout",
    		409 => "Conflict",
    		410 => "Gone",
    		411 => "Length Required",
    		412 => "Precondition Failed",
    		413 => "Request Entity Too Large",
    		414 => "Request Uri Too Long",
    		415 => "Unsupported Media Type",
    		416 => "Requested Range Not Satisfiable",
    		417 => "Expectation Failed",
    		500 => "Internal Server Error",
    		501 => "Not Implemented",
    		502 => "Bad Gateway",
    		503 => "Service Unavailable",
    		504 => "Gateway Timeout",
    		505 => "Http Version Not Supported"
	    );
	    
	    /**
	     * Returns the HTTP response status code
	     *
	     * @return int
	     */
	    public function getCode()
	    {
	        return (int)substr( $this->name, -3 );
	    }
	    
	    /**
	     * Returns the HTTP response status message
	     * 
	     * @return string
	     */
	    public function __toString()
	    {
	        return self::$statuses[$this->getCode()];
	    }
	    
	    /**
	     * Returns the HttpStatus enumeration value basing on 
	     * the given status code
	     * 
	     * @internal
	     * @param int $code
	     * @return Curly\HttpStatus
	     * @throws \InvalidArgumentException
	     */
	    public static function _fromCode( $code )
	    {
	        $code = (int)$code;
	        if( isset( self::$statuses[$code] ) )
	        {
	            $methodName = self::$statuses[$code];
	            $methodName = str_replace( array( " ", "-" ), "", $methodName );
	            $methodName .= "_{$code}";
	            
	            return self::$methodName();
	        }
	        else
	        {
	            throw new \InvalidArgumentException( "Unrecognised HTTP status code '{$code}'" );
	        }
	    }
	    
	    
	    /**
	     * 100 Continue
	     *
	     * @return Curly\HttpStatus
	     */
	    public static function Continue_100()
	    {
	        return parent::___getInstance( __FUNCTION__ );
	    }
	    
	    /**
	     * 101 Switching Protocols
	     *
	     * @return Curly\HttpStatus
	     */
	    public static function SwitchingProtocols_101()
	    {
	        return parent::___getInstance( __FUNCTION__ );
	    }
	    
	    /**
	     * 200 OK
	     *
	     * @return Curly\HttpStatus
	     */
	    public static function OK_200()
	    {
	        return parent::___getInstance( __FUNCTION__ );
	    }
	    
	    /**
	     * 201 Created
	     *
	     * @return Curly\HttpStatus
	     */
		public static function Created_201()
	    {
	        return parent::___getInstance( __FUNCTION__ );
	    }

	    /**
	     * 202 Accepted
	     *
	     * @return Curly\HttpStatus
	     */
		public static function Accepted_202()
	    {
	        return parent::___getInstance( __FUNCTION__ );
	    }
	    
	    /**
	     * 203 Non Authorative Information
	     *
	     * @return Curly\HttpStatus
	     */
		public static function NonAuthoritativeInformation_203()
	    {
	        return parent::___getInstance( __FUNCTION__ );
	    }
	    
	    /**
	     * 204 No Content
	     *
	     * @return Curly\HttpStatus
	     */
		public static function NoContent_204()
	    {
	        return parent::___getInstance( __FUNCTION__ );
	    }
	    
	    /**
	     * 205 Reset Content
	     *
	     * @return Curly\HttpStatus
	     */
		public static function ResetContent_205()
	    {
	        return parent::___getInstance( __FUNCTION__ );
	    }
	    
	    /**
	     * 206 Partial Content
	     *
	     * @return Curly\HttpStatus
	     */
		public static function PartialContent_206()
	    {
	        return parent::___getInstance( __FUNCTION__ );
	    }
	    
	    /**
	     * 300 Multiple Choices
	     *
	     * @return Curly\HttpStatus
	     */
		public static function MultipleChoices_300()
	    {
	        return parent::___getInstance( __FUNCTION__ );
	    }
	    
	    /**
	     * 301 Moved Permanently
	     *
	     * @return Curly\HttpStatus
	     */
		public static function MovedPermanently_301()
	    {
	        return parent::___getInstance( __FUNCTION__ );
	    }
	    
	    /**
	     * 302 Found
	     *
	     * @return Curly\HttpStatus
	     */
		public static function Found_302()
	    {
	        return parent::___getInstance( __FUNCTION__ );
	    }
	    
	    /**
	     * 303 See Other
	     *
	     * @return Curly\HttpStatus
	     */
		public static function SeeOther_303()
	    {
	        return parent::___getInstance( __FUNCTION__ );
	    }

	    /**
	     * 304 Not Modified
	     *
	     * @return Curly\HttpStatus
	     */
		public static function NotModified_304()
	    {
	        return parent::___getInstance( __FUNCTION__ );
	    }

	    /**
	     * 305 Use Proxy
	     *
	     * @return Curly\HttpStatus
	     */
		public static function UseProxy_305()
	    {
	        return parent::___getInstance( __FUNCTION__ );
	    }
	    
	    /**
	     * 306 Unused
	     *
	     * @return Curly\HttpStatus
	     */
		public static function Unused_306()
	    {
	        return parent::___getInstance( __FUNCTION__ );
	    }
        
	    /**
	     * 307 Temporary Redirect
	     *
	     * @return Curly\HttpStatus
	     */
		public static function TemporaryRedirect_307()
	    {
	        return parent::___getInstance( __FUNCTION__ );
	    }
        
	    /**
	     * 400 Bad Request
	     *
	     * @return Curly\HttpStatus
	     */
		public static function BadRequest_400()
	    {
	        return parent::___getInstance( __FUNCTION__ );
	    }
	    
	    /**
	     * 401 Unauthorized
	     *
	     * @return Curly\HttpStatus
	     */
		public static function Unauthorized_401()
	    {
	        return parent::___getInstance( __FUNCTION__ );
	    }
	    
	    /**
	     * 402 Payment Required
	     *
	     * @return Curly\HttpStatus
	     */
		public static function PaymentRequired_402()
	    {
	        return parent::___getInstance( __FUNCTION__ );
	    }

	    /**
	     * 403 Forbidden
	     *
	     * @return Curly\HttpStatus
	     */
		public static function Forbidden_403()
	    {
	        return parent::___getInstance( __FUNCTION__ );
	    }
	    
	    /**
	     * 404 Not Found
	     *
	     * @return Curly\HttpStatus
	     */
		public static function NotFound_404()
	    {
	        return parent::___getInstance( __FUNCTION__ );
	    }
	    
	    /**
	     * 405 Method Not Allowed
	     *
	     * @return Curly\HttpStatus
	     */
		public static function MethodNotAllowed_405()
	    {
	        return parent::___getInstance( __FUNCTION__ );
	    }
	    
	    /**
	     * 406 Not Acceptable
	     *
	     * @return Curly\HttpStatus
	     */
		public static function NotAcceptable_406()
	    {
	        return parent::___getInstance( __FUNCTION__ );
	    }
	    
	    /**
	     * 407 Proxy Authentication Required
	     *
	     * @return Curly\HttpStatus
	     */
		public static function ProxyAuthenticationRequired_407()
	    {
	        return parent::___getInstance( __FUNCTION__ );
	    }
        
	    /**
	     * 408 Request Timeout
	     *
	     * @return Curly\HttpStatus
	     */
		public static function RequestTimeout_408()
	    {
	        return parent::___getInstance( __FUNCTION__ );
	    }
	    
	    /**
	     * 409 Conflict
	     *
	     * @return Curly\HttpStatus
	     */
		public static function Conflict_409()
	    {
	        return parent::___getInstance( __FUNCTION__ );
	    }
	    
	    /**
	     * 410 Gone
	     *
	     * @return Curly\HttpStatus
	     */
		public static function Gone_410()
	    {
	        return parent::___getInstance( __FUNCTION__ );
	    }
        
	    /**
	     * 411 Length Required
	     *
	     * @return Curly\HttpStatus
	     */
		public static function LengthRequired_411()
	    {
	        return parent::___getInstance( __FUNCTION__ );
	    }
	    
	    /**
	     * 412 Precondition Failed
	     *
	     * @return Curly\HttpStatus
	     */
		public static function PreconditionFailed_412()
	    {
	        return parent::___getInstance( __FUNCTION__ );
	    }
        
	    /**
	     * 413 Request Entity Too Large
	     *
	     * @return Curly\HttpStatus
	     */
		public static function RequestEntityTooLarge_413()
	    {
	        return parent::___getInstance( __FUNCTION__ );
	    }
	    
	    /**
	     * 414 Request Uri Too Long
	     *
	     * @return Curly\HttpStatus
	     */
		public static function RequestUriTooLong_414()
	    {
	        return parent::___getInstance( __FUNCTION__ );
	    }
        
	    /**
	     * 415 Unsupported Media Type
	     *
	     * @return Curly\HttpStatus
	     */
		public static function UnsupportedMediaType_415()
	    {
	        return parent::___getInstance( __FUNCTION__ );
	    }
	    
	    /**
	     * 416 Request Range Not Satisfiable
	     *
	     * @return Curly\HttpStatus
	     */
		public static function RequestedRangeNotSatisfiable_416()
	    {
	        return parent::___getInstance( __FUNCTION__ );
	    }
        
	    /**
	     * 417 Expectation Failed
	     *
	     * @return Curly\HttpStatus
	     */
		public static function ExpectationFailed_417()
	    {
	        return parent::___getInstance( __FUNCTION__ );
	    }
	    
	    /**
	     * 500 Internal Server Error
	     *
	     * @return Curly\HttpStatus
	     */
		public static function InternalServerError_500()
	    {
	        return parent::___getInstance( __FUNCTION__ );
	    }
        
	    /**
	     * 501 Not Implemented
	     *
	     * @return Curly\HttpStatus
	     */
		public static function NotImplemented_501()
	    {
	        return parent::___getInstance( __FUNCTION__ );
	    }
        
	    /**
	     * 502 Bad Gateway
	     *
	     * @return Curly\HttpStatus
	     */
		public static function BadGateway_502()
	    {
	        return parent::___getInstance( __FUNCTION__ );
	    }
	    
	    /**
	     * 503 Service Unavailable
	     *
	     * @return Curly\HttpStatus
	     */
		public static function ServiceUnavailable_503()
	    {
	        return parent::___getInstance( __FUNCTION__ );
	    }
	    
	    /**
	     * 504 Gateway Timeout
	     *
	     * @return Curly\HttpStatus
	     */
		public static function GatewayTimeout_504()
	    {
	        return parent::___getInstance( __FUNCTION__ );
	    }
        
	    /**
	     * 505 HTTP Version Not Supported
	     *
	     * @return Curly\HttpStatus
	     */
		public static function HttpVersionNotSupported_505()
	    {
	        return parent::___getInstance( __FUNCTION__ );
	    }
	}
}